#include "VoxelOctree.h"
#include <algorithm>

using namespace std;

#define r16 rand() % 16
#define r128 rand() % 128
#define r256 rand() % 256

VoxelOctree::VoxelOctree(Vector3d pos,double size) : RenderObject(pos)
{
	start = new VONode(pos,pos+size);
	for(int x= 0;x < size;x++)
	{
		for(int y = 0;y < size;y++)
		{
			for(int z = 0;z < size;z++)
			{
				if(Vector3d::distance(Vector3d(size/2,size/2,size/2),Vector3d(x,y,z)) < size/3)
				{
					if(!(Vector3d::distance(Vector3d(size/2,size/2,size/2),Vector3d(x,y,z)) < size/4))
					{
						//if(rand() % 1000 > 750)
						set(x,y,z);
					}
					
				//}

			}
		}
		}
	}

	/*
	start->set(0,0,0);
	start->set(0,0,15);

	start->set(0,15,0);
	start->set(0,15,15);

	start->set(15,0,0);
	start->set(15,0,15);

	start->set(15,15,0);
	start->set(15,15,15);
	*/

}

void VoxelOctree::set(int x,int y,int z)
{
	start->set(x + position.x,y + position.y,z + position.z);
}


VoxelOctree::~VoxelOctree(void)
{
}



TraceResult VoxelOctree::collision(const Ray &ray)
{
	return start->hit(ray);
}
